#include<bits/stdc++.h>
using namespace std;


string addZero(int y) {
    string s = to_string(y);
    while(s.size() != 4)
        s = "0" + s;
    return s;
}


int countNums(int y) {
    string s = addZero(y);

    set<char> st;
    for(auto i : s)
        st.insert(i);

    return st.size();
}


signed main() {
    int y, n, x;
    cin >> y >> n;

    int birth = y;
    for(; countNums(y) != n; y++);
    cout << y - birth << " " << addZero(y);
    return 0;
}

